package com.zzw.zim.security.serivce;

import com.zzw.zim.system.entitys.SysUserEntity;
import com.zzw.zim.system.dao.SysUserDao;
import com.zzw.zim.system.service.SysUserDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 账号登录 UserDetailsService

 * @author XiaoJie
 * @date 2025/05/12 10:21:10
 */
@Service
@AllArgsConstructor
public class UserDetailServiceImpl implements UserDetailsService {
	private final SysUserDetailsService sysUserDetailsService;
	private final SysUserDao sysUserDao;

	@Override
	public UserDetails loadUserByUsername (String userName) throws UsernameNotFoundException {
		SysUserEntity userEntity = sysUserDao.getByUsername(userName);
		if (userEntity == null) {
			throw new UsernameNotFoundException("用户名或密码错误");
		}

		return sysUserDetailsService.getUserDetails(userEntity);
	}
}
